home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 4 / ETO Development Tools 4.iso / Essentials / MacApp Documentation / MacApp.TECH$ Archives / 1990 / Dec 90 / MacApp.Tech$ 12⁄14⁄90 / 2491-Re IApplicaiton & sp-Dec90 < prev    next >
Encoding:
Text File  |  1991-03-06  |  7.1 KB  |  195 lines  |  [TEXT/GEOL]

  1. Item    0536839                         11-Dec-90        11:55PST
  2.  
  3. From:   DAWSON.M                        Dawson, Mark
  4.  
  5. To:     CSX.ACCOUNT1                    CSX Technology, Scott Steffan,PRT
  6.         MACAPP.TECH$                    MacApp Technical
  7.  
  8. ------------------------------------------------------------------------------
  9.  
  10. Sub:    Re: IApplicaiton & splash…
  11.  
  12. Thomas,
  13.  
  14. Below is code (C++) that we use for our splash screen (drawn in our
  15. IApplication). Our splash screen draws a "progress" bar, that is controlled
  16. from the application.  Clicking on the splash screen makes it go away.  Its not
  17. perfect, but it does work.
  18.  
  19. Hope this helps,
  20.  
  21. Mark
  22. ------------------- cut here, if you don't want to view code ------------------
  23. ----------- class definitions -------------------
  24. // ==================================================================
  25. class TSplashScreen {  // don't want this handle-based, so don't sub-class it
  26.    DialogRecordfSplashDlogRecord;  // holds the dialog record (we want it in our
  27.    // memory, otherwise it will be allocated in the regular heap && will
  28.    // fragment the memory.
  29.    short   fItemType;     // user dialog item type for the incrementing bar
  30.    Handle  fItem;       // item # for splash screen bar
  31.    Handle  fControlHandle;  // handle to
  32.    short   fNumInc;    // #of times this is going to be called
  33.    short   fCount;      // #of times this has been called
  34.    RectfBarPiece[kMaxNumSplashScreenCalls];// array of bar pieces to draw
  35.    RectfBar;           // total bar size (from resource)
  36.    Boolean fWantGoAwayScreen;
  37. public:
  38.    TSplashScreen( short num_sections, Boolean want_goaway_screen = FALSE);
  39.    inline ~TSplashScreen() { CloseDialog((DialogPtr)&fSplashDlogRecord); }
  40.    virtual pascal void UpdateSplashScreen();   // calls the draw dialog routine
  41. };
  42. ----------- resources -------------------
  43. // splash screen resources
  44. resource 'DLOG' (kSplashID, "Splash Screen", purgeable) {
  45.    {72, 40, 182, 472},
  46.    dBoxProc,
  47.    invisible,
  48.    noGoAway,
  49.    0x0,
  50.    kSplashID,
  51.    "Splash"
  52. };
  53.  
  54. resource 'DITL' (1300, "Splash Screen", purgeable) {
  55.    {   /* array DITLarray: 4 elements */
  56.    /* [1] */
  57.    {78, 88, 92, 388},
  58.    UserItem {
  59.    disabled
  60.    },
  61.    /* [2] */
  62.    {17, 16, 49, 48},
  63.    Icon {
  64.    disabled,
  65.    1300
  66.    },
  67.    /* [3] */
  68.    {23, 152, 39, 312},
  69.    StaticText {
  70.    disabled,
  71.    "Loading MacTest™..."
  72.    },
  73.    /* [4] */
  74.    {41, 152, 57, 312},
  75.    StaticText {
  76.    disabled,
  77.    ""
  78.    }
  79.    }
  80. };
  81.  
  82. resource 'ICON' (kSplashID, "Splash icon") {
  83.    $"0007 FF80 0008 0000 0008 7E20 0008 0120"
  84.    $"0008 0120 0408 0120 0C08 0120 0808 0120"
  85.    $"6608 0120 9908 0120 8108 FE20 8008 0020"
  86.    $"8008 0020 4A00 1F20 3400 0020 00FC 0020"
  87.    $"0300 0000 0401 FFF0 0400 0008 03E0 1FE4"
  88.    $"0010 0552 0010 00A9 0020 0001 0020 01FE"
  89.    $"0018 0000 0000 0000 0000 0000 24C6 EE6E"
  90.    $"3D28 4884 25E8 4E44 2528 4824 2526 4EC4"
  91. };
  92.  
  93. ----------- how its used in our IApplication -------------------
  94. TMyApplication::IApplication()
  95.   {
  96.     ...
  97.       TSplashScreen splashScreen (15);
  98.     ...
  99.       splashScreen.UpdateSplashScreen();
  100.       ...
  101.       splashScreen.UpdateSplashScreen();
  102.       ...
  103.   }
  104. ----------- code -------------------
  105. /****************************************************************************\
  106. *                                                         *
  107. *  METHOD TSplashScreen                                        *
  108. *  Initialize the splashscreen Object.                             *
  109. *                                                         *
  110. *  1. To avoid heap fragmentation, we allocate space for the DialogRecord   *
  111. *     on the stack, as a local variable in this procedure, so that the      *
  112. *     dialog record *won't* be allocated as a non-relocatable block at      *
  113. *     the  bottom of the heap.                                   *
  114. *  2. If we were to pass NIL to GetNewCenteredDialog for the dStorage,     *
  115. *     then the call to GetNewDialog would allocate the dialog record as a   *
  116. *     non-relocatable block at the bottom of the heap leading to heap       *
  117. *     fragmentation during InitUMacApp's call to MoreMasters.             *
  118. *                                                         *
  119. \****************************************************************************/
  120. TSplashScreen::TSplashScreen( short num_sections, Boolean want_goaway_screen)
  121.   {
  122.    DialogPtr gSplashDlog = (DialogPtr)&fSplashDlogRecord;
  123.    if ((GetNewCenteredDialog(kSplashID, (Ptr)gSplashDlog, (GrafPtr)-1)))
  124.    {
  125.    /* indicator bar */
  126.    GetDItem(gSplashDlog, kProgressBar, &fItemType, &fItem, &fBar);
  127.  
  128.    if (num_sections >= kMaxNumSplashScreenCalls)   // range check
  129.      num_sections = kMaxNumSplashScreenCalls;
  130.    fNumInc =   num_sections;
  131.    fCount = 0;
  132.    // -----
  133.    // now build the boxe sizes that fill in the bar
  134.    //
  135.    short i, x = fBar.left, y = x, top = fBar.top, bot = fBar.bottom;
  136.    short tot_len = fBar.right - fBar.left + 1;
  137.    short     size_inc = tot_len/fNumInc,      // what % of total size to draw
  138.          slop_inc = tot_len % fNumInc;    // what to have to add to last draw
  139.                                             // to fill the rest of the prog bar
  140.    for (i=0; i < fNumInc; i++) // build boxes to draw
  141.      {
  142.        y += size_inc + (i == fNumInc-2 ? slop_inc : 0);
  143.          fBarPiece[i].top = top;
  144.        fBarPiece[i].bottom = bot;
  145.        fBarPiece[i].left = x;
  146.        fBarPiece[i].right = y;
  147.      }
  148.    ShowWindow(gSplashDlog);
  149.    DrawDialog(gSplashDlog);
  150.  
  151.    fWantGoAwayScreen = want_goaway_screen; // TRUE if user can click on splash
  152.                                            // screen and make it go away
  153.    }
  154.   }
  155.  
  156. /****************************************************************************\
  157. *                                                         *
  158. *  METHOD UpdateSplashScreen                                       *
  159. *  Draws the next bar increment in the splash screen.                   *
  160. *                                                         *
  161. \****************************************************************************/
  162. pascal void TSplashScreen::UpdateSplashScreen()
  163.   {
  164.    EventRecord theEvent;
  165.    if (GetNextEvent(mDownMask,&theEvent))  // Was a mouse down in cancel button?
  166.      {
  167.      if (IsDialogEvent(&theEvent)) // see if the mouse down was in a dialog
  168.       {
  169.            // assume (for now) that the only dialog event would be a mouse click
  170.         // in this splash screen (that isn't 100% certain in a multi-finder
  171.         // enviroment, but it'll do for now.   Assume further that if the
  172.         // dialog is clicked on anywhere (not only in the "cancel" button,
  173.         // that the user wants the dialog to disappear
  174.         //
  175.         fCount = fNumInc;  // set so updates won't occur
  176.         HideWindow((DialogPtr)&fSplashDlogRecord);
  177.      }
  178.      }
  179.    if (fCount < fNumInc)   // don't do…should only fail if some one called a new
  180.        {   // UpdateSplashScreen() and didn't update the # of members to call (in
  181.         // the init section)
  182.            HLock((Handle)this);
  183.        GrafPtr curGraphPort;
  184.        GetPort (&curGraphPort);
  185.          SetPort ((DialogPtr)&fSplashDlogRecord);
  186.  
  187.          EraseRect(&fBar);
  188.          FrameRect(&fBar);
  189.          FillRect(&fBarPiece[fCount++],qd.gray);
  190.          SetPort(curGraphPort);
  191.            HUnlock((Handle)this);
  192.        }
  193.   }
  194.  
  195.